package com.xli.organ.ou.frameou.mapper;

import com.xli.organ.ou.frameou.entity.FrameOu;
import com.xli.organ.ou.frameou.entity.OuCache;
import com.xli.organ.user.frameuser.entity.FrameUser;
import com.xli.organ.user.frameuser.entity.UserCache;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface IOuCacheMapper {

    IOuCacheMapper INSTANCE = Mappers.getMapper(IOuCacheMapper.class);

    OuCache toCacheEntity(FrameOu frameOu);

    List<OuCache> toCacheList(List<FrameOu> frameOuList);

    List<FrameOu> toEntityList(List<OuCache> ouCacheList);

    default List<FrameOu> toEntityList(List<OuCache> cacheList, Function<Long, FrameOu> query) {
        return cacheList.stream().map(cache -> query.apply(cache.getId())).collect(Collectors.toList());
    }
}
